from flask import jsonify, current_app
from flask_jwt_extended import jwt_required
from ..services import DashboardService
from ..utils import success_response, error_response
from . import api

@api.route('/dashboard/stats', methods=['GET'])
@jwt_required()
def get_stats():
    """获取系统统计信息"""
    try:
        stats = DashboardService.get_stats()
        return success_response(stats, '获取成功')
    except Exception as e:
        current_app.logger.error(f'获取统计信息错误: {str(e)}')
        return error_response('获取统计信息失败', 500)

@api.route('/dashboard/activities', methods=['GET'])
@jwt_required()
def get_recent_activities():
    """获取最近活动记录"""
    try:
        activities = DashboardService.get_recent_activities()
        return success_response(activities, '获取成功')
    except Exception as e:
        current_app.logger.error(f'获取活动记录错误: {str(e)}')
        return error_response('获取活动记录失败', 500)